package com.edu.exam.entity.curriculum.questionbank;

import com.edu.exam.enums.questionbank.OptionType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 单选题选项实体类
 * 对应数据库表：sc_options
 *
 * 根据B-02-03-03单选题管理子模块设计文档实现
 * 管理单选题的选项信息，包括选项内容、显示顺序、选项类型、媒体文件等。
 * 支持多种选项类型（文本、图片、音频、视频）和完整的生命周期管理。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "sc_options")
@Comment("单选题选项表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SingleChoiceOption {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 选项唯一标识符
     */
    @NotBlank(message = "选项ID不能为空")
    @Size(max = 50, message = "选项ID长度不能超过50个字符")
    @Column(name = "option_id", nullable = false, length = 50, unique = true)
    private String optionId;

    /**
     * 关联的单选题ID
     */
    @NotNull(message = "题目ID不能为空")
    @Column(name = "question_id", nullable = false)
    private String questionId;

    /**
     * 选项显示顺序（从1开始）
     */
    @NotNull(message = "选项顺序不能为空")
    @Column(name = "option_order", nullable = false)
    private Integer optionOrder;

    /**
     * 选项内容
     */
    @NotBlank(message = "选项内容不能为空")
    @Column(name = "content", nullable = false, columnDefinition = "TEXT")
    private String content;

    /**
     * 选项类型
     */
    @NotNull(message = "选项类型不能为空")
    @Enumerated(EnumType.STRING)
    @Column(name = "option_type", nullable = false, length = 10)
    private OptionType optionType;

    /**
     * 选项内容类型（HTML、Markdown、纯文本等）
     */
    @Size(max = 20, message = "内容类型长度不能超过20个字符")
    @Column(name = "content_type", length = 20)
    private String contentType;

    /**
     * 媒体文件URL
     */
    @Size(max = 500, message = "媒体文件URL长度不能超过500个字符")
    @Column(name = "media_url", length = 500)
    private String mediaUrl;

    /**
     * 媒体文件类型（图片、音频、视频）
     */
    @Size(max = 20, message = "媒体文件类型长度不能超过20个字符")
    @Column(name = "media_type", length = 20)
    private String mediaType;

    /**
     * 是否为正确答案
     */
    @Column(name = "is_correct", nullable = false)
    private Boolean isCorrect;

    /**
     * 选项解析
     */
    @Column(name = "option_explanation", columnDefinition = "TEXT")
    private String optionExplanation;

    /**
     * 选项干扰性评分（0-1，越高越具有干扰性）
     */
    @Column(name = "distraction_score", precision = 3, scale = 2)
    private Float distractionScore;

    /**
     * 选择次数统计
     */
    @Column(name = "select_count", nullable = false)
    private Integer selectCount;

    /**
     * 正确选择次数统计
     */
    @Column(name = "correct_select_count", nullable = false)
    private Integer correctSelectCount;

    /**
     * 选择率
     */
    @Column(name = "select_rate", precision = 5, scale = 4)
    private Float selectRate;

    /**
     * 软删除标识
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 创建人
     */
    @Size(max = 50, message = "创建人长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;
}